package com.xiyou.weblog.common.domain.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xiyou.weblog.common.domain.dos.ArticleContentDO;

/**
 * @author xiyou
 * @description 文章内容模块
 */
public interface ArticleContentMapper extends BaseMapper<ArticleContentDO> {

    /**
     * 根据文章 ID 删除记录
     */
    default int deleteByArticleId(Long articleId) {
        return delete(Wrappers.<ArticleContentDO>lambdaQuery()
                .eq(ArticleContentDO::getArticleId, articleId));
    }

    /**
     * 根据文章Id查询
     */
    default ArticleContentDO selectByArticleId(Long articleId) {
        return selectOne(Wrappers.<ArticleContentDO>lambdaQuery()
                .eq(ArticleContentDO::getArticleId, articleId));
    }

    /**
     * 通过文章ID更新
     */
    default int updateByArticleId(ArticleContentDO articleContentDO){
        return update(articleContentDO, Wrappers.<ArticleContentDO>lambdaUpdate()
        .eq(ArticleContentDO::getArticleId, articleContentDO.getArticleId()));
    }
}
